package com.zkca.xf.ui.adapter;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zkca.xf.R;
import com.zkca.xf.model.javabean.Subject;

import java.util.List;



public class SwipAdapter extends RecyclerView.Adapter<SwipAdapter.ViewHolder> {

    private List<Subject> datas;
    private Context mContext;
    private LayoutInflater mLiLayoutInflater;
    private int height;

    public SwipAdapter(List<Subject> datas, Context context,int height) {
        this.datas = datas;
        this.mContext = context;
        this.height=height;
        this.mLiLayoutInflater = LayoutInflater.from(mContext);
    }


    @Override
    public SwipAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(mLiLayoutInflater.inflate(R.layout.homefrag_item, parent, false));
    }

    @Override
    public void onBindViewHolder(SwipAdapter.ViewHolder holder, int position) {
        holder.tv_title.setText(datas.get(position).getTitle());
        holder.img.setImageResource(datas.get(position).getImg());
        boolean ismodule = datas.get(position).isModule();
        if (ismodule){
            holder.ismodule.setVisibility(View.GONE);
        }else {
            holder.ismodule.setVisibility(View.VISIBLE);
            holder.ll_item.setClickable(false);
        }
        GridLayoutManager.LayoutParams linearParams =(GridLayoutManager.LayoutParams) holder.ll_item.getLayoutParams();
        linearParams.height=height;

        holder.ll_item.setLayoutParams(linearParams);
    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView tv_title;
        ImageView img;
        ImageView ismodule;
        public LinearLayout ll_item, ll_hidden;

        public ViewHolder(View itemView) {
            super(itemView);
            tv_title = (TextView) itemView.findViewById(R.id.title_homeitem);
            img = (ImageView) itemView.findViewById(R.id.icon_homeitem);
            ismodule = (ImageView) itemView.findViewById(R.id.ismodule);

            ll_item = (LinearLayout) itemView.findViewById(R.id.ll_item);
            ll_hidden = (LinearLayout) itemView.findViewById(R.id.ll_hidden);
        }
    }
}
